''' Init DB'''
from db_interface import *
foo = dbApi('sqlite3')
db = foo.open()
db.initDB()
db.rebuildDB()




''' Rebuild DB '''
from db_interface import *
foo = dbApi('sqlite3')
db = foo.open()
db.rebuildDB()


''' Query DB '''
from db_interface import *
foo = dbApi('sqlite3')
db = foo.open()
sql = "select * from users"
db.query(sql)


'''Get userData'''
from model import userControl
foo = userControl()
foo.checkLogin('kfox', 'thispass')



'''Get All userData'''
from model import userControl
foo = userControl()
foo.getUsers()

'''Test User login control '''
from model import userControl
userCtrlImp = userControl()
login = 'kfox'
password = 'kevin'
user = userCtrlImp.checkLogin(login, password)


from db_interface import *
foo = dbApi('sqlite3')
db = foo.open()

for thisNum in range(1,20):
    sql = """ insert into users ( uname,password,namefirst,namelast,email,isadmin)
values ('user%(num)s', '9d5e3ecdeb4cdb7acfd63075ae046672', 'Guest%(num)s', 'User%(num)s', 'user%(num)s@test.com', 0);""" % {'num': thisNum}
    print sql 
    db.execute(sql)




'''
-- No Conflict
select
e.mid as event, 
e.mstarttime as start, 
e.mendtime as end, 
e.mdescription as title,
e.mhostid as host,
e.mroomid as room,
a.uid as attendee,
a.asid as attendRespId
from 
events e 
LEFT JOIN 
attendees a 
ON 
e.mid = a.mid 
where 
e.mstarttime BETWEEN 1312335000 and 1312338600
or
e.mendtime BETWEEN  1312335000 and 1312338600
AND
e.mstatusid = 1;




-- CONFLICT

select
e.mid as event, 
e.mstarttime as start, 
e.mendtime as end, 
e.mdescription as title,
e.mhostid as host,
e.mroomid as room,
a.uid as attendee,
a.asid as attendRespId
from 
events e 
LEFT JOIN 
attendees a 
ON 
e.mid = a.mid 
where 

e.mstarttime >= 1314840600
OR
e.mendtime <= 1314844200
AND
e.mstatusid = 1;


select
e.mid as event, 
e.mstarttime as start, 
e.mendtime as end, 
e.mdescription as title,
e.mhostid as host,
e.mroomid as room,
a.uid as attendee,
a.asid as attendRespId
from 
events e 
LEFT JOIN 
attendees a 
ON 
e.mid = a.mid 
where 
e.mstarttime BETWEEN 1314840600 and 1314844200
OR
e.mendtime BETWEEN 1314840600 AND 1314844200
AND
e.mstatusid = 1;

select
e.mid as event, 
e.mstarttime as start, 
e.mendtime as end, 
e.mdescription as title,
e.mhostid as host,
e.mroomid as room,
a.uid as attendee,
a.asid as attendRespId
from 
events e 
LEFT JOIN 
attendees a 
ON 
e.mid = a.mid 
where 
e.mstarttime BETWEEN 1314797400 and 1314801000
AND
e.mendtime BETWEEN 1314797400 and 1314801000
AND
e.mstatusid = 1;




'''